﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;

namespace MedReg.Classes
{
    [Serializable]
    public class PostGraduateEducation : ISerializable
    {
        private EducationInstitution baseOrgField;

        private PostGraduationEducationType typeField;

        private System.Nullable<System.DateTime> dateBeginField;

        private System.Nullable<System.DateTime> dateEndField;

        private System.Nullable<System.DateTime> dateDocumField;

        private AcademicDegree degreeField;

        private string diplomaSerieField;

        private string diplomaNumberField;

        private SertificateSpeciality postGraduationSpecialityField;

        private static readonly PostGraduateEducation theOneObject = new PostGraduateEducation();

        private Employee employeeField;

        public static PostGraduateEducation GetPostGraduateEducation()
        {
            return theOneObject;
        }
        /// <remarks/>
        public EducationInstitution BaseOrg
        {
            get
            {
                return this.baseOrgField;
            }
            set
            {
                this.baseOrgField = value;
            }
        }

        /// <remarks/>
        public PostGraduationEducationType Type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
        public System.Nullable<System.DateTime> DateBegin
        {
            get
            {
                return this.dateBeginField;
            }
            set
            {
                this.dateBeginField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
        public System.Nullable<System.DateTime> DateEnd
        {
            get
            {
                return this.dateEndField;
            }
            set
            {
                this.dateEndField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
        public System.Nullable<System.DateTime> DateDocum
        {
            get
            {
                return this.dateDocumField;
            }
            set
            {
                this.dateDocumField = value;
            }
        }

        /// <remarks/>
        public AcademicDegree Degree
        {
            get
            {
                return this.degreeField;
            }
            set
            {
                this.degreeField = value;
            }
        }

        /// <remarks/>
        public string DiplomaSerie
        {
            get
            {
                return this.diplomaSerieField;
            }
            set
            {
                this.diplomaSerieField = value;
            }
        }

        /// <remarks/>
        public string DiplomaNumber
        {
            get
            {
                return this.diplomaNumberField;
            }
            set
            {
                this.diplomaNumberField = value;
            }
        }

        /// <remarks/>
        public SertificateSpeciality PostGraduationSpeciality
        {
            get
            {
                return this.postGraduationSpecialityField;
            }
            set
            {
                this.postGraduationSpecialityField = value;
            }
        }
        
        public Employee Employee
        {
            get
            {
                return employeeField;
            }
            set
            {
                employeeField = value;
            }
        }

        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //throw new NotImplementedException();
            info.AddValue("BaseOrg", baseOrgField);
            info.AddValue("Type", typeField);
            info.AddValue("DateBegin", dateBeginField);
            info.AddValue("DateEnd", dateEndField);
            info.AddValue("DateDocum", dateDocumField);
            info.AddValue("Degree", degreeField);
            info.AddValue("DiplomaSerie", diplomaSerieField);
            info.AddValue("DiplomaNumber", diplomaNumberField);
            info.AddValue("PostGraduationSpeciality", postGraduationSpecialityField);
        }
        public PostGraduateEducation()
        {
        }
        public List<Classes.PostGraduateEducation> getPostGraduateEducationList(Classes.ArrayOfEmployee sEmployee)
        {

            foreach (var emp in sEmployee)
            {
                foreach (var postGraduateEducation in emp.EmployeePostGraduateEducation)
                {
                    postGraduateEducation.Employee = emp;
                }
            }

            //var awd = sEmployee
            //    .SelectMany(award => award.EmployeeAwards, (Employees, Awards) => new { Employees, Awards })
            //    .Select(AwardsEx => new { Employee = AwardsEx.Employees, AwardsEx.Awards }).ToList();

            var cr = sEmployee.SelectMany(em => em.EmployeePostGraduateEducation).ToList();

            return cr;
        }
    }
}
